/**
 * 
 */
var _playerNamed = 0;

$(document).ready(function()
	{
	$('#regForm').submit(function()
		{
		_playerNamed = $("input:first").val();
		//Nime piirangud
		if (_playerNamed.length>0 && _playerNamed.length<8)
		{
			//Status: 1- join queue, 2 - hosting, 3 - playing, 0 - left
			$.post("./lobby",{Name:String(_playerNamed),Status:1},function(){
				parent.$("a#name").attr("href",String(_playerNamed));
				parent.$.fancybox.close();
			});
			$("#joinBtn").attr('disabled',true);
				
			}
		return false;
		});
	$('#googleLoginBtn').click(function()
	{
		gapi.auth.authorize({'client_id':'687872041218.apps.googleusercontent.com','scope':'https://www.googleapis.com/auth/userinfo.profile'},function(token)
		{
			var jsonFromGoogle = (gapi.client.request({'path':'/oauth2/v1/userinfo?alt=json&access_token='+String(token.access_token)}));
			jsonFromGoogle.execute(function(data) 
			{
				_playerNamed=data.name;
				$.post("./lobby",{Name:String(_playerNamed),Status:1},function()
				{
					parent.$("a#name").attr("href",String(_playerNamed));
					parent.$.fancybox.close();
				});
			});
			
		});
	});
});